<?php
/**
 * 商品规格服务层
 * @author maniac
 */
namespace app\common\service;

use app\common\model\GoodSpecValue;

class GoodSpecs extends Base
{
    /**
     * 获取商品规格
     * @param  string $spec_ids 商品规格 id
     */
    public function specs($spec_ids)
    {
        $where = [
            ['spec_id', 'in', $spec_ids],
        ];
        $values = GoodSpecValue::field('id,spec_id,spec_value_name,spec_value_data')->where($where)->order('list_order DESC,id ASC')->select();
        $data   = [];
        foreach ($values as $v) {
            $data[$v['spec_id']]['id']        = $v['spec_id'];
            $data[$v['spec_id']]['key']       = $v['spec_key'];
            $data[$v['spec_id']]['show_type'] = $v['show_type'];
            $data[$v['spec_id']]['value'][]   = $v;
        }
        return array_values($data);
    }
}
